<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="utf-8">
    <title>table模块快速使用</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">

    <script src="/static/layui/layui.js"></script>
    <script src="/static/js/jquery.min.js"></script>
</head>
<body>


<div class="layui-form layui-form-pane" style="margin: 5px">
    <button class="layui-btn" id="add" lay-even="add" <c:if test="${model.glCreate != 1}">style="visibility: hidden"</c:if>>Add</button>
</div>

<div class="layui-form">
    <table class="layui-table">
        <colgroup>
            <col width="240">
            <col width="240">
            <col>
            <col>
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>Menu name</th>
            <th>Jump link</th>
            <th>High menu</th>
            <th>Sort</th>
            <th>Action bar</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${limitList}" var="limit" varStatus="status">
            <tr>
                <td>${limit.limitName}</td>
                <td>${limit.limitUrl}</td>
                <td>${limit.parentLimitName}</td>
                <td>${limit.sortId}</td>
                <td>
                    <c:choose>
                        <c:when test="${limit.isSys==1}">
                            System Configuration
                        </c:when>
                        <c:when test="${limit.isSys!=1}">
                                <button class="layui-btn layui-btn-sm layui-btn-normal" onClick="update('${limit.limitId}')">edit</button>
                                <button class="layui-btn layui-btn-sm layui-btn-normal" onClick="del('${limit.limitId}')">del</button>
                        </c:when>
                        <c:otherwise>
                            <c:if test="${model.glCreate != 1}">
                                <button class="layui-btn layui-btn-sm layui-btn-normal" onClick="update('${limit.limitId}')">edit</button>
                            </c:if>
                            <c:if test="${model.glCreate != 1}">
                                <button class="layui-btn layui-btn-sm layui-btn-normal" onClick="del('${limit.limitId}')">del</button>
                            </c:if>
                        </c:otherwise>
                    </c:choose>
                </td>
            </tr>
            <c:if test="${limit.list != null}">
                <c:forEach items="${limit.list}" var="limit1" varStatus="status1">
                    <tr>
                        <td>&nbsp;&nbsp;|--|--&nbsp;&nbsp;${limit1.limitName}</td>
                        <td>${limit1.limitUrl}</td>
                        <td>${limit1.parentLimitName}</td>
                        <td>${limit1.sortId}</td>
                        <td>
                            <c:choose>
                                <c:when test="${limit1.isSys==1}">
                                    System Configuration
                                </c:when>
                                <c:otherwise>
                                    <button class="layui-btn layui-btn-sm layui-btn-normal" onClick="update('${limit1.limitId}')">edit</button>
                                    <button class="layui-btn layui-btn-sm layui-btn-normal" onClick="del('${limit1.limitId}')">del</button>
                                </c:otherwise>
                            </c:choose>
                        </td>
                    </tr>
                </c:forEach>
            </c:if>
        </c:forEach>
        </tbody>
    </table>
</div>

</body>
<script>
    layui.use(['util','jquery', 'layer', 'table'], function () {

        var table = layui.table;

        //让层自适应iframe
        $('#add').on('click', function(){
            var index = layer.open({
                title: 'Information',
                type: 2,
                content: '/manage/limit/goAdd',
                area: ['500px', '450px'],
                offset: ['200px', '650px'],
                maxmin: true,//最大最小化
                end: function () {
                    location.reload();
                }
            });
            parent.layer.iframeAuto(index);
        });
    });


    // 删除
    function del(id){
        layer.confirm('Can\'t recover after delete, really delete？', function(index){
            $.ajax({
                url : '/manage/limit/del',
                type : 'post',
                dataType : 'json',
                data : {id : id},
                success : function (data) {
                    if (data.code=="200"){
                        layer.msg(data.msg,{icon: 1, time: 500},function () {
                            window.location.reload();
                        });
                    }else{
                        layer.msg(data.msg,{icon: 1, time: 1000});
                    }
                }
            })

        });
    };

    // 修改
    function update(id){
        var index = layer.open({
            title: 'Information',
            type: 2,
            content: '/manage/limit/goEdit?id='+id,
            area: ['400px', '450px'],
            maxmin: true,
            end: function () {
                location.reload();
            }
        });
        parent.layer.iframeAuto(index);
    };

</script>

</html>
